package cn.zn.modules.zzsys.enums;

import cn.zn.modules.zzsys.cur.entity.vo.TeacherPgroupVO;
import cn.zn.modules.zzsys.enums.po.ProcessGroupPermissions;
import com.beust.jcommander.internal.Lists;
import lombok.Getter;

import java.util.*;

/**
 * 流程用户组
 *
 * @author zn
 */
@Getter
public enum ProcessGroupTypeEnum {
    /**
     * 院长
     */
    YZ("yz", "院长", false, true, 10, ""),
    /**
     * 分管领导
     */
    FGLD("fgld", "分管领导", false, true, 20, ""),
    /**
     * 主管财务院长
     */
    ZGCWYZ("zgcwyz", "主管财务院长", false, true, 30, ""),
    /**
     * 财务处长
     */
    CWCZ("cwcz", "财务处长", false, true, 40, "可修改单据的校内预算和财政预算"),
    /**
     * 财务部长
     */
    CWBZ("cwbz", "总会计师", false, true, 50, "为报销单设置财政预算"),
    /**
     * 部门领导
     */
    BMLD("bmld", "部门领导", true, true, 60, ""),
    /**
     * 制单员
     */
    ZDY("zdy", "报账员", true, true, 70, ""),
    /**
     * 院长办公会
     */
    YZBGH("yzbgh", "院长办公会", false, true, 80, ""),
    /**
     * 纪检部
     */
    JJB("jjb", "纪检部", false, true, 90, ""),
    /**
     * 人事部
     */
    RSB("rsb", "人事部", false, true, 100, ""),
    /**
     * 经费支出审核组
     */
    JFZCSHZ("jfzcshz", "经费支出审核组", false, true, 110, ""),
    /**
     * 专项小组
     */
    ZXXZ("zxxz", "专项小组", false, true, 120, ""),
    /**
     * 出纳
     */
    CN("cn", "出纳", false, true, 130, ""),
    /**
     * 会计
     */
    KJ("kj", "录入会计", false, true, 140, ""),
    /**
     * 会计
     */
    SHKJ("shkj", "审核会计", false, true, 150, ""),
    /**
     * 退回确认
     */
    THQR("thqr", "退回确认", false, false, 160, ""),

    ;
    private String code;
    private String name;
    /**
     * 给人员设置角色时，是否必须选择部门
     */
    private Boolean mustDept;
    /**
     * 是否需要设置用户，某些流程角色仅用于标识流程节点
     */
    private Boolean setupUser;
    /**
     * 排序
     */
    private Integer sortNum;
    /**
     * 说明
     */
    private String instructions;

    ProcessGroupTypeEnum(String code, String name, Boolean mustDept, Boolean setupUser, Integer sortNum, String instructions) {
        this.code = code;
        this.name = name;
        this.mustDept = mustDept;
        this.setupUser = setupUser;
        this.sortNum = sortNum;
        this.instructions = instructions;
    }

    public static ProcessGroupTypeEnum findByCode(String code) {
        ProcessGroupTypeEnum e = null;
        for (int i = 0; i < values().length; i++) {
            if (values()[i].getCode().equals(code)) {
                e = values()[i];
                break;
            }
        }
        return e;
    }

    public static Set<Map<String, Object>> keyValues() {
        Set<Map<String, Object>> pgs = new LinkedHashSet<>();
        Map<String, Object> pgMap = null;
        ProcessGroupTypeEnum[] processGroupEnums = values();
        for (int i = 0; i < processGroupEnums.length; i++) {
            pgMap = new HashMap<>();
            pgMap.put("code", processGroupEnums[i].getCode());
            pgMap.put("name", processGroupEnums[i].getName());
            pgMap.put("mustDept", processGroupEnums[i].getMustDept());
            pgs.add(pgMap);
        }
        return pgs;
    }

    /**
     * 得到可设置的流程用户组列表
     *
     * @param processGroupPermissions
     * @return
     */
    public static List<ProcessGroupTypeEnum> listForSetup(ProcessGroupPermissions processGroupPermissions) {
        List<ProcessGroupTypeEnum> list = Lists.newArrayList();
        ProcessGroupTypeEnum[] processGroupEnums = values();
        for (ProcessGroupTypeEnum e : processGroupEnums) {
            if (!e.setupUser) {
                continue;
            }
            Boolean canSetup = processGroupPermissions.canSetup(e);
            if (canSetup == null || canSetup) {
                list.add(e);
            }
        }
        return list;
    }

}
